﻿
@{
    ViewBag.Title = "BudgetNotificationAdd";
    Layout = "~/Views/Shared/_LayoutMain.cshtml";
}

@section css {
    <link href="~/Assets/css/lib/bootstrap-select.css" rel="stylesheet" />
    <link href="~/Assets/css/lib/bootstrap-datetimepicker.min.css" rel="stylesheet" />
    <link href="~/Assets/css/lib/fileinput.css" rel="stylesheet" />
    <style>
        th {
            text-align: center;
            font-weight: bold;
        }

        td {
            text-align: center;
            vertical-align: middle;
        }
    </style>
}
<div class="page-content" ng-cloak ng-controller="SafetyCostController" ng-init="SelectedOption=[];
     page='@(Request.QueryString["page"].IsEmpty() ? "1" : Request.QueryString["page"])';
       Id='@(Request.QueryString["Id"].IsEmpty() ? "" : Request.QueryString["Id"])';
     AddModel.ApplyDate = '@DateTime.Now.ToString("yyyy-MM-dd")';
     ApplyItems = [];
    TotalAmount=0;

     GetSafetyBudgetApplyDetail(Id);
           GetSafetyFormFile(Id);
    ">
    <div class="load" ng-show="DataLoading">
        <div class="loader">
            <svg version="1.1" id="loader-1" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve">
            <path fill="#000" d="M43.935,25.145c0-10.318-8.364-18.683-18.683-18.683c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615c8.072,0,14.615,6.543,14.615,14.615H43.935z">
            <animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite" />

			</path>
		</svg>
            <div class="load-msg">正在加载...</div>
        </div>
    </div>
    <div class="page-heading">
        <h1>编辑预算申请</h1>
        <div class="options">
            <div class="btn-toolbar">

            </div>
        </div>
    </div>
    <ol class="breadcrumb">
        <li><a>主体业务</a></li>
        <li><a>安全费用</a></li>
        <li class="active"><a>编辑预算申请</a></li>
    </ol>

    <div class="container-fluid">
        <div class="row">
            <form class="form-horizontal row-border">
                <div class="col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading"><h2>编辑预算申请</h2></div>
                        <div class="panel-body">
                            <div class="form-group">
                                <label class="col-sm-1 control-label"><b style="color:red;">*</b>预算年度：</label>
                                <div class="col-sm-4">
                                    <select class="form-control" ng-model="BudgetDetail.Years">
                                        <option selected value="">请选择预算预算年度</option>
                                        <option value="@DateTime.Now.Year">@DateTime.Now.Year</option>
                                        <option value="@(DateTime.Now.Year+1)">@(DateTime.Now.Year+1)</option>
                                    </select>
                                </div>
                                <label class="col-sm-1 control-label"><b style="color:red;"></b>申请人：</label>
                                <div class="col-sm-4">
                                    <input class="form-control" type="text" value="{{User.UserName}}" readonly />
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label"><b style="color:red;"></b>申请部门：</label>
                                <div class="col-sm-4">
                                    <input class="form-control" type="text" value="{{User.DepartmentName}}" readonly />
                                </div>
                                <label class="col-sm-1 control-label"><b style="color:red;"></b>申请时间：</label>
                                <div class="col-sm-4">
                                    <datepicker id="startTime" option="datetimeOption" format="L" ng-model="BudgetDetail.ApplyDate"></datepicker>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label"><b style="color:red;"></b>已添加预算项：</label>
                                <div class="col-sm-10">
                                    <table class="table table-striped table-bordered table-hover">
                                        <thead>
                                            <tr>
                                                <th style="width:5%">序号</th>
                                                <th style="width:30%">使用范围</th>
                                                <th style="width:10%">预计金额</th>
                                                <th style="width:10%">备注</th>
                                                <th style="width:10%">操作</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr ng-show="BudgetDetail.ApplyItems==0">
                                                <td colspan="4" style="text-align:center;vertical-align:middle;line-height:30px;">没有数据</td>
                                            </tr>
                                            <tr ng-repeat="x in BudgetDetail.ApplyItems">
                                                <td>{{$index+1}}</td>
                                                <td>{{x.RangeModel.Title +'.'+ x.RangeModel.Content}}</td>
                                                <td>{{x.Amount}} {{x.Amount|TransCurrency}}</td>
                                                <td>{{x.Remark}}</td>
                                                <td><a ng-click="DeleteBudgetApplyItems(x,BudgetDetail.ApplyItems,ApplyItems);CalcBudgetApplyEditTotal(BudgetDetail.ApplyItems,ApplyItems);" class="btn btn-danger btn-xs btn-label"><i class="fa fa-trash"></i>删除</a></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <div class="form-group" ng-show="ApplyItems.length==0">
                                <label class="col-sm-1 control-label"><b style="color:red;"></b>预算项：</label>
                                <div class="col-sm-1">
                                    <button class="btn btn-primary"  ng-click="AddApplyItem(ApplyItems);">添加</button>
                                </div>
                            </div>
                            <div class="form-group" ng-repeat="x in ApplyItems">
                                <label class="col-sm-1 control-label"><b style="color:red;">*</b>使用范围{{$index+1}}：</label>
                                <div class="col-sm-1">
                                    <a class="btn btn-sm btn-default btn-label" ng-click="GetUsageRangeList();SetCurrentIndex(x.Index);" data-toggle="modal" href="#UsageRangeModal"><i class="fa fa-cog"></i>选择使用范围</a>
                                </div>
                                <div class="col-sm-3" id="range_{{$index}}">

                                </div>
                                <label class="col-sm-1 control-label"><b style="color:red;">*</b>申请金额(元)：</label>
                                <div class="col-sm-1">
                                    <input type="number" class="form-control" ng-model="x.Amount" ng-change="CalcBudgetApplyEditTotal(BudgetDetail.ApplyItems,ApplyItems);" />
                                </div>
                                <label class="col-sm-1 control-label"><b style="color:red;"></b>备注</label>
                                <div class="col-sm-2">
                                    <input type="tex" class="form-control" ng-model="x.Amount" ng-change="CalcBudgetApplyEditTotal(BudgetDetail.ApplyItems,ApplyItems);" />
                                </div>
                                <div class="col-sm-1">
                                    <button class="btn btn-danger" ng-click="RemoveApplyItems(x,ApplyItems);CalcTotalApplyAmount(ApplyItems);CalcBudgetApplyEditTotal(BudgetDetail.ApplyItems,ApplyItems);">移除</button>
                                </div>
                                <div class="col-sm-1">
                                    <button class="btn btn-primary" ng-show="$index==ApplyItems.length-1" ng-click="AddApplyItem(ApplyItems);CalcBudgetApplyEditTotal(BudgetDetail.ApplyItems,ApplyItems);">添加</button>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label"><b style="color:red;"></b>合计金额(元)：</label>
                                <div class="col-sm-2">
                                    <input type="text" class="form-control" readonly value="{{TotalAmount}}" />
                                </div>
                                <label class="col-sm-2 control-label" style="text-align:left;">{{TotalAmount|TransCurrency}}</label>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label"><b style="color:red;"></b>备注：</label>
                                <div class="col-sm-8">
                                    <textarea type="text" class="form-control" ng-model="BudgetDetail.Remark"></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label"><b style="color:red;"></b>附件：</label>
                                <div class="col-sm-8">
                                    <table class="table table-striped table-bordered table-hover">
                                        <thead>
                                            <tr>
                                                <th style="width:5%">序号</th>
                                                <th style="width:30%">文件名称</th>
                                                <th style="width:10%">文件大小(kb)</th>
                                                <th style="width:10%">操作</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr ng-show="FileList.length==0">
                                                <td colspan="4" style="text-align:center;vertical-align:middle;line-height:30px;">没有数据</td>
                                            </tr>
                                            <tr ng-repeat="x in FileList">
                                                <td ng-bind="$index+1"></td>
                                                <td ng-bind="x.FileName"></td>
                                                <td ng-bind="x.FileSize"></td>
                                                <td>
                                                    <a href="../Download/DownloadFile?FileId={{x.FileId}}" class="btn btn-success btn-xs btn-label"><i class="fa fa-download"></i>下载</a>
                                                    <a ng-click="DeleteSafetyCostFile(x,FileList);" class="btn btn-danger btn-xs btn-label"><i class="fa fa-trash"></i>删除</a>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label"><b style="color:red;"></b>文件上传：</label>
                                <div class="col-sm-8">
                                    <input type="file" class="form-control" id="taskfile" />
                                </div>
                            </div>
                        </div>
                        <div class="panel-footer">
                            <div class="col-md-4">
                            </div>
                            <div class="col-md-1">
                                <button class="btn-primary btn" ng-click="EditBudgetApply(BudgetDetail,0,ApplyItems,page)">保存</button>
                            </div>
                            <div class="col-md-1">
                                <button class="btn-primary btn" ng-click="EditBudgetApply(BudgetDetail,1,ApplyItems,page)">提交</button>
                            </div>
                            <div class="col-md-1">
                                <a href="BudgetApplyList?page={{page}}" class="btn-default btn">返回</a>
                            </div>
                            <div class="col-md-3">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="modal fade" id="UsageRangeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog" style="min-width:1250px;">
                        <div class="modal-content" style="min-height: 700px;">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h2 class="modal-title">选择使用范围</h2>
                            </div>
                            <div class="modal-body" style="min-height: 660px;">
                                <div class="form-group">
                                    <div class="col-sm-12">
                                        <div class="checkbox" style="margin-top:5px;" ng-repeat="x in UsageRangeList"><label><input type="radio" value="{{x.Id}}" name="usagerangelist">&nbsp;&nbsp;{{x.Title}}&nbsp;.&nbsp;{{x.Content}}</label></div>
                                    </div>
                                </div>

                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal" id="btn_close">关闭</button>
                                <button type="button" class="btn btn-primary" data-dismiss="modal" ng-click="SelectUsageRange(CurrentIndex,ApplyItems);">提交</button>
                            </div>
                        </div>

                    </div><!-- /.modal-dialog -->
                </div><!-- /.modal -->
            </form>
        </div>

    </div>

</div>

@section Js{
    <script src="~/Assets/plugins/form-ckeditor/ckeditor.js"></script>
    <script src="~/Assets/js/libs/upload.js"></script>
    <script src="~/Assets/js/pg/SafetyCost.js?v=@DateTime.Now.ToString("yyMMddHHmm")"></script>
    <script src="~/Assets/js/libs/moment.min.js"></script>
    <script src="~/Assets/js/libs/locales/date/zh-cn.js"></script>
    <script src="~/Assets/js/libs/bootstrap-datetimepicker.min.js"></script>
    <script src="~/Assets/js/libs/angularjs-datepicker.js"></script>
    <script src="~/Assets/js/libs/fileinput.js"></script>
    <script src="~/Assets/js/libs/zh.js"></script>
    <script>
        $('#SelectedCheckList').sortable({
            connectWith: ".sortable-connected",
            receive: function (event, ui) {
                var lists = $('.sortable-connected');
                for (var i = lists.length - 1; i >= 0; i--) {
                    if ($(lists[i]).children().length < 1) $(lists[i]).html('');
                };
            }
        });
    </script>
}
